<?php

namespace App\Http\Requests\Backend\AppUpdate;

use Illuminate\Foundation\Http\FormRequest;

class AppUpdateRequest extends FormRequest
{
    public $routeName;

    public function __construct(){
        $this->routeName = \Route::currentRouteName();
        parent::__construct();
    }
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->routeName){
            case 'app_update.index':
                return $this->indexRules();
                break;
            case 'app_update.store':
                return $this->storeRules();
                break;
            default:
                return [];
        }
    }

    protected function indexRules(){
        return [];
    }

    protected function storeRules(){
        return [
            'app_update_time' => 'required|date',
            'title' => 'required',
            'version' => 'required',
            'install_pkg_url' => 'required',
            'app_update_text' => 'required',
            'ios_pkg_url' => 'required',
            'is_force' => 'required'
        ];
    }

    public function messages() {
        switch ($this->routeName){
            case 'app_update.index':
                return $this->indexMessages();
                break;
            case 'app_update.store':
                return $this->storeMessages();
                break;
            default:
                return [];
        }
    }

    protected function indexMessages(){
        return [];
    }

    protected function storeMessages(){
        return [
            'app_update_time.required' => '更新时间不能为空',
            'app_update_time.date' => '更新时间类型错误',
            'title.required' => '标题不能为空',
            'version.required' => '版本不能为空',
            'install_pkg_url.required' => '安装包地址不能为空',
            'app_update_text.required' => '更新文本不能为空',
            'ios_pkg_url.required' => 'ios安装包不能为空',
            'is_force.required' => '强制更新选项不能为空'
        ];
    }
}
